package com.woniuxy.pxxt.controller;



import com.woniuxy.pxxt.common.result.Result;
import com.woniuxy.pxxt.common.vo.CourseEditVo;
import com.woniuxy.pxxt.common.vo.CourseManageVo;
import com.woniuxy.pxxt.dto.CourseVideoScheduleDto;
import com.woniuxy.pxxt.entity.Course;
import com.woniuxy.pxxt.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




/**
 * 是培训项目下的阶段(PxxtCourse)表控制层
 *
 * @author makejava
 * @since 2022-03-07 16:33:15
 */
@RestController
@RequestMapping("/course")
@Api(value = "培训项目下的阶段")
public class CourseController {
    @Autowired
    private CourseService courseService;

//    @ApiOperation(value = "查询所有经理人")
//    @GetMapping("/manager")
//    public Result queryManagerName(){
//        return courseService.queryManagerName();
//    }
//
//
//    @ApiOperation(value = "查询所有培训")
//    @GetMapping("/train")
//    public Result queryAllTrain(){
//        return courseService.queryAllTrain();
//    }

    @ApiOperation(value = "课程管理查询所有条件")
    @GetMapping("courseManage/condition")
    public Result queryAllTrain(){
        return courseService.queryAllCondition();
    }

    /***
     * <p>TODO: 课程表分页查询
     * @description
     * @since 2022/3/8 10:49
     * @author QinYD
     * @param currentPage       当前页
     * @param pageSize          分页大小
     * @param courseManageVo    课程管理页面vo
     * @return com.woniuxy.pxxt.common.result.Result
     */

    @ApiOperation(value = "课程管理课程表分页查询")
    @PostMapping("courseManage/{currentPage}/{pageSize}")
    public Result queryByPage(@PathVariable("currentPage") int currentPage,
                              @PathVariable("pageSize") int pageSize,
                              @RequestBody CourseManageVo courseManageVo){
        return courseService.queryByPage(currentPage,pageSize,courseManageVo);
    }
//    @ApiOperation(value = "课程表分页查询加培训id筛选")
//    @PostMapping("/{trainId}/{currentPage}/{pageSize}")
//    public Result queryByPage(@PathVariable("trainId") int trainId,
//                              @PathVariable("currentPage") int currentPage,
//                              @PathVariable("pageSize") int pageSize,
//                              @RequestBody Course course){
//        return courseService.queryByPage(trainId,currentPage,pageSize,course);
//    }

    /***
     * <p>TODO: 按照课程主键id查询
     * @description
     * @since 2022/3/8 10:51
     * @author QinYD
     * @param id    主键
     * @return com.woniuxy.pxxt.common.result.Result
     */
    @ApiOperation(value = "课程管理课程表按照课程主键id查询")
    @GetMapping("courseManage/{id}")
    public Result queryById(@PathVariable("id") String id){
        return courseService.queryById(Integer.valueOf(id));
    }

    /***
     * <p>TODO: 课程表新增方法
     * @description
     * @since 2022/3/8 11:06
     * @author QinYD
     * @param courseEditVo 课程表对象
     * @return com.woniuxy.pxxt.common.result.Result
     */

    @ApiOperation(value = "课程管理课程表新增方法,成功返回主键id")
    @PostMapping("courseManage")
    public Result add(@RequestBody CourseEditVo courseEditVo){
        System.out.println(courseEditVo);
        return courseService.insert(courseEditVo);
    }

    /***
     * <p>TODO: 课程表更新方法，更新成功返回主键id
     * @description
     * @since 2022/3/8 11:58
     * @author QinYD
     * @param courseEditVo
     * @return com.woniuxy.pxxt.common.result.Result
     */
    @ApiOperation(value = "课程管理课程表更新方法,成功返回主键id")
    @PutMapping("courseManage")
    public Result edit(@RequestBody  CourseEditVo courseEditVo){
        return courseService.update(courseEditVo);
    }

    /***
     * <p>TODO: 课程表按id来逻辑删除
     * @description
     * @since 2022/3/8 12:03
     * @author QinYD
     * @param id
     * @return com.woniuxy.pxxt.common.result.Result
     */
    @ApiOperation(value = "课程管理课程表逻辑删除方法")
    @DeleteMapping("courseManage/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        return courseService.deleteById(id);
    }

    /***
     * <p>TODO: 用课程的id获取课程下的所有文件
     * @description
     * @since 2022/3/14 15:27
     * @author QinYD
     * @param
     * @return com.woniuxy.pxxt.common.result.Result
     */
    @ApiOperation(value = "课程页面的数据查询")
    @GetMapping("{id}")
    public Result findCourse(@PathVariable("id") Integer id){

        return courseService.findCourse(id);
    }


    @ApiOperation(value = "查询用户课程视频的进度记录")
    @PostMapping("schedule")
    public Result queryCourseVideoSchedule(@RequestBody CourseVideoScheduleDto courseVideoScheduleDto){
        return courseService.queryCourseVideoSchedule(courseVideoScheduleDto);
    }

    @ApiOperation(value = "保存用户课程视频的进度")
    @PutMapping("schedule")
    public Result saveSchedule(@RequestBody CourseVideoScheduleDto courseVideoScheduleDto){
        return courseService.saveSchedule(courseVideoScheduleDto);
    }

    @ApiOperation(value = "查询用户该课程的所有视频的进度记录")
    @PostMapping("allSchedule")
    public Result queryCourseAllVideoSchedule(@RequestBody CourseVideoScheduleDto courseVideoScheduleDto){
        return courseService.queryCourseAllVideoSchedule(courseVideoScheduleDto);
    }
}

